#include "stdafx.h"
#include "vCommUtils.h"

namespace vview
{

CVWindow* GetParentWindow(CVView* pView)
{
	CVView* pParentView = pView;
	while ((NULL != pParentView) && (!OBJECT_DERIVEDFROM(pParentView, CVWindow)))
		pParentView = pParentView->GetParent();
	
	return (CVWindow*)pParentView;
}

ShiftState VKeyToShiftState(WORD keys)
{
	ShiftState shift = 0;
	if (HAS_FLAG(keys, MK_SHIFT))	INCLUDE_FLAG(shift, SSTATE_SHIFT);
	if (HAS_FLAG(keys, MK_CONTROL)) INCLUDE_FLAG(shift, SSTATE_CTRL);
	if (::GetKeyState(VK_MENU) < 0) INCLUDE_FLAG(shift, SSTATE_ALT);
	return shift;
}

vview::ShiftState KeyDataToShiftState( long keyData )
{
	#define ALT_MASK 0x20000000
	ShiftState shift = 0;
	if (::GetKeyState(VK_SHIFT) < 0)	INCLUDE_FLAG(shift, SSTATE_SHIFT);
	if (::GetKeyState(VK_CONTROL) < 0)	INCLUDE_FLAG(shift, SSTATE_CTRL);
	if (HAS_FLAG(keyData, ALT_MASK))	INCLUDE_FLAG(shift, SSTATE_ALT);
	return shift;
}


}